/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.ManyToOne;
import util.PQPEntityListener;

/**
 *
 * @author wei
 */
@Entity(name="ProductQuantityPrice")
@EntityListeners(PQPEntityListener.class)
public class ProductQuantityPriceEntity extends DataObjectEntity implements Serializable {
    @ManyToOne
    private ProductEntity product;
    private long quantity;
    private double price;
    private double pricePerUnit;

   
    
    
    @ManyToOne
    private SalesInquiryEntity salesInquiry;

    @ManyToOne
    private SalesQuotationEntity salesQuotation;
    
    @ManyToOne
    private PurchaseOrderEntity purchaseOrder;
    
    @ManyToOne
    private SalesOrderEntity salesOrder;
    
    @ManyToOne
    private BackorderEntity backorder;
    
    

    public ProductQuantityPriceEntity() {
        super();
    }

    public BackorderEntity getBackorder() {
        return backorder;
    }
    
    
    public void setBackorder(BackorderEntity backorder) {
        this.backorder = backorder;
    }
    
    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public ProductEntity getProduct() {
        return product;
    }

    public void setProduct(ProductEntity product) {
        this.product = product;
    }

    public long getQuantity() {
        return quantity;
    }

    public void setQuantity(long quantity) {
        this.quantity = quantity;
    }

    public PurchaseOrderEntity getPurchaseOrder() {
        return purchaseOrder;
    }

    public void setPurchaseOrder(PurchaseOrderEntity purchaseOrder) {
        this.purchaseOrder = purchaseOrder;
    }

    public SalesQuotationEntity getSalesQuotation() {
        return salesQuotation;
    }

    public void setSalesQuotation(SalesQuotationEntity salesQuotation) {
        this.salesQuotation = salesQuotation;
    }

    public SalesInquiryEntity getSalesInquiry() {
        return salesInquiry;
    }

    public void setSalesInquiry(SalesInquiryEntity salesInquiry) {
        this.salesInquiry = salesInquiry;
    }

    public SalesOrderEntity getSalesOrder() {
        return salesOrder;
    }

    public void setSalesOrder(SalesOrderEntity salesOrder) {
        this.salesOrder = salesOrder;
    }

    @Override
    public String childToString() {
        return "ProductQuantityPriceEntity{" + "product=" + product + ", quantity=" + quantity + ", price=" + price + ", salesInquiry=" + salesInquiry + ", salesQuotation=" + salesQuotation + ", purchaseOrder=" + purchaseOrder + ", salesOrder=" + salesOrder + '}';
    }

    public double getPricePerUnit() {
        return pricePerUnit;
    }

    public void setPricePerUnit(double pricePerUnit) {
        this.pricePerUnit = pricePerUnit;
    }
    
    public void calculatePricePerUnit(){
        pricePerUnit = 0;
        if(quantity>0)
            pricePerUnit = price/quantity;
        System.out.println("set unit price: " + pricePerUnit);
    }
    
}
